//
//  AnalysisURLCiphertext.m
//  MIS Cloud
//
//  Created by goldeney on 14-4-1.
//  Copyright (c) 2014年 goldeneye. All rights reserved.
//

#import "AnalysisURLCiphertext.h"
#import "GTMBase64.h"

@implementation AnalysisURLCiphertext

+ (NSDictionary*)analysisURLString:(NSString*)requestString
{
    //URL数据节点判断和过滤
    NSString *protocol = [NSString stringWithFormat:@"%@://",CSMonitorNodeOrder];
    
    //事件截取判断
    if ([requestString hasPrefix:protocol]) {
        NSString *requestContent = [requestString substringFromIndex:[protocol length]];
        NSData* response = [self analysisCiphertextData:requestContent];
        if (!response) return nil;
        
        //解析JSON类型数据
        NSError *error = nil;
        NSDictionary *webViewDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
        if (webViewDic && !error){
            return webViewDic;
        }
    }
    
    return nil;
}

#pragma mark-
#pragma mark 解析密文

+ (NSData*)analysisCiphertextData:(NSString*)urlString
{
    //字符串转码为UTF-8
    //urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    //将Base64格式数据解码
    NSData* response = [GTMBase64 decodeString:urlString ];
    return response;
}

@end
